/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.xinxi.dms.view;

import com.xinxi.dms.po.Room;
import com.xinxi.dms.po.Student;
import com.xinxi.dms.service.IRoomService;
import com.xinxi.dms.service.IStudentService;
import com.xinxi.dms.service.RoomServiceIMPL;
import com.xinxi.dms.service.StudentServiceIMPL;
import com.xinxi.dms.util.FrameUtil2;
import java.util.List;
import java.util.Vector;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;

/**
 *
 * @author zhigu
 */
public class StudentFrame extends javax.swing.JInternalFrame {
    IRoomService roomService = new RoomServiceIMPL();
    IStudentService studentService = new StudentServiceIMPL();
    /**
     * Creates new form StudentFrame
     */
    public StudentFrame() {
        initComponents();
        List<Student> list = studentService.findAll();
        refresh(list);
        
        this.btnupdate.setEnabled(false);
        this.btndelete.setEnabled(false);
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jRadioButtonMenuItem1 = new javax.swing.JRadioButtonMenuItem();
        jScrollPane1 = new javax.swing.JScrollPane();
        tabStudent = new javax.swing.JTable();
        jLabel1 = new javax.swing.JLabel();
        boxbuildingno = new javax.swing.JComboBox<>();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        jLabel9 = new javax.swing.JLabel();
        boxunitno = new javax.swing.JComboBox<>();
        txtstuid = new javax.swing.JTextField();
        jLabel10 = new javax.swing.JLabel();
        boxroomno = new javax.swing.JComboBox<>();
        txtstusex = new javax.swing.JTextField();
        txtstuname = new javax.swing.JTextField();
        txtstuage = new javax.swing.JTextField();
        txtstuschool = new javax.swing.JTextField();
        txtstuphone = new javax.swing.JTextField();
        txtstucard = new javax.swing.JTextField();
        btninto = new javax.swing.JButton();
        btnupdate = new javax.swing.JButton();
        btncancel = new javax.swing.JButton();
        btndelete = new javax.swing.JButton();

        jRadioButtonMenuItem1.setSelected(true);
        jRadioButtonMenuItem1.setText("jRadioButtonMenuItem1");

        setClosable(true);
        setIconifiable(true);
        setMaximizable(true);
        setTitle("学生管理系统");
        addInternalFrameListener(new javax.swing.event.InternalFrameListener() {
            public void internalFrameActivated(javax.swing.event.InternalFrameEvent evt) {
            }
            public void internalFrameClosed(javax.swing.event.InternalFrameEvent evt) {
            }
            public void internalFrameClosing(javax.swing.event.InternalFrameEvent evt) {
                formInternalFrameClosing(evt);
            }
            public void internalFrameDeactivated(javax.swing.event.InternalFrameEvent evt) {
            }
            public void internalFrameDeiconified(javax.swing.event.InternalFrameEvent evt) {
            }
            public void internalFrameIconified(javax.swing.event.InternalFrameEvent evt) {
            }
            public void internalFrameOpened(javax.swing.event.InternalFrameEvent evt) {
            }
        });

        tabStudent.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "学生编号", "学生姓名", "学生性别", "学生年龄", "学生院校", "学生手机号", "学生身份证号", "楼号", "单元号", "房间号"
            }
        ) {
            boolean[] canEdit = new boolean [] {
                false, false, false, false, false, false, false, false, false, false
            };

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        tabStudent.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                tabStudentMouseClicked(evt);
            }
        });
        jScrollPane1.setViewportView(tabStudent);
        if (tabStudent.getColumnModel().getColumnCount() > 0) {
            tabStudent.getColumnModel().getColumn(0).setResizable(false);
            tabStudent.getColumnModel().getColumn(1).setResizable(false);
            tabStudent.getColumnModel().getColumn(2).setResizable(false);
            tabStudent.getColumnModel().getColumn(3).setResizable(false);
            tabStudent.getColumnModel().getColumn(4).setResizable(false);
            tabStudent.getColumnModel().getColumn(5).setResizable(false);
            tabStudent.getColumnModel().getColumn(6).setResizable(false);
            tabStudent.getColumnModel().getColumn(7).setResizable(false);
            tabStudent.getColumnModel().getColumn(8).setResizable(false);
            tabStudent.getColumnModel().getColumn(9).setResizable(false);
        }

        jLabel1.setText("学生编号：");

        boxbuildingno.setModel(new javax.swing.DefaultComboBoxModel<>(new String[] { "请选择", "25", "23" }));
        boxbuildingno.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                boxbuildingnoActionPerformed(evt);
            }
        });

        jLabel2.setText("学生手机号：");

        jLabel3.setText("学生姓名：");

        jLabel4.setText("学生性别：");

        jLabel5.setText("学生年龄：");

        jLabel6.setText("学生院校：");

        jLabel7.setText("学生身份证号：");

        jLabel8.setText("楼号：");

        jLabel9.setText("单元号：");

        boxunitno.setModel(new javax.swing.DefaultComboBoxModel<>(new String[] { "请选择" }));
        boxunitno.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                boxunitnoActionPerformed(evt);
            }
        });

        txtstuid.setEditable(false);
        txtstuid.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtstuidActionPerformed(evt);
            }
        });

        jLabel10.setText("房间号：");

        boxroomno.setModel(new javax.swing.DefaultComboBoxModel<>(new String[] { "请选择" }));
        boxroomno.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                boxroomnoActionPerformed(evt);
            }
        });

        btninto.setText("添加");
        btninto.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnintoActionPerformed(evt);
            }
        });

        btnupdate.setText("修改");
        btnupdate.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnupdateActionPerformed(evt);
            }
        });

        btncancel.setText("取消");
        btncancel.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btncancelActionPerformed(evt);
            }
        });

        btndelete.setText("删除");
        btndelete.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btndeleteActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane1)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                                .addComponent(jLabel1)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(txtstuid, javax.swing.GroupLayout.PREFERRED_SIZE, 73, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jLabel3))
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jLabel2)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(txtstuphone, javax.swing.GroupLayout.PREFERRED_SIZE, 73, javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jLabel7)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(txtstucard))
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(txtstuname, javax.swing.GroupLayout.PREFERRED_SIZE, 73, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(43, 43, 43)
                                .addComponent(jLabel4)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(txtstusex, javax.swing.GroupLayout.PREFERRED_SIZE, 73, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(27, 27, 27)
                                .addComponent(jLabel5)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(txtstuage, javax.swing.GroupLayout.PREFERRED_SIZE, 73, javax.swing.GroupLayout.PREFERRED_SIZE))))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabel10)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(boxroomno, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(554, 554, 554)))
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(27, 27, 27)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jLabel8)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(boxbuildingno, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(31, 31, 31)
                                .addComponent(jLabel9)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(boxunitno, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jLabel6)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(txtstuschool, javax.swing.GroupLayout.PREFERRED_SIZE, 73, javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addContainerGap(81, Short.MAX_VALUE))
                    .addGroup(layout.createSequentialGroup()
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(btninto)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(btnupdate)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(btndelete)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(btncancel)
                        .addGap(67, 67, 67))))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 249, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(54, 54, 54)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(jLabel3)
                    .addComponent(jLabel4)
                    .addComponent(jLabel5)
                    .addComponent(jLabel6)
                    .addComponent(txtstuid, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(txtstusex, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(txtstuname, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(txtstuage, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(txtstuschool, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 25, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(boxbuildingno, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel2)
                    .addComponent(jLabel7)
                    .addComponent(jLabel8)
                    .addComponent(jLabel9)
                    .addComponent(boxunitno, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(txtstuphone, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(txtstucard, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel10)
                            .addComponent(boxroomno, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(45, 45, 45))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(btncancel)
                            .addComponent(btnupdate)
                            .addComponent(btninto)
                            .addComponent(btndelete))
                        .addGap(23, 23, 23))))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void boxbuildingnoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_boxbuildingnoActionPerformed
        // TODO add your handling code here:
        //清空单元号内容
        this.boxunitno.removeAllItems();
        //向单元号添加一个请选择
        this.boxunitno.addItem("请选择");
        //获取楼号组合框中的内容
        String buildingno = (String)this.boxbuildingno.getSelectedItem();
        List<Room> roomlist = roomService.getRoomUnitno(buildingno);
        for(Room room:roomlist){
            //遍历集合
            this.boxunitno.addItem(room.getUnitno());
         //   this.boxroomno.addItem(room.getRoomgno());
        }
                
    }//GEN-LAST:event_boxbuildingnoActionPerformed

    private void boxunitnoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_boxunitnoActionPerformed
        // TODO add your handling code here:
        this.boxroomno.removeAllItems();
        //向单元号添加一个请选择
        this.boxroomno.addItem("请选择");
        //获取楼号组合框中的内容
        String buildingno = (String)this.boxbuildingno.getSelectedItem();
        String unitno = (String)this.boxunitno.getSelectedItem();
        List<Room> roomlist = roomService.getRoomRoomno(buildingno, unitno);
        for(Room room : roomlist){
            this.boxroomno.addItem(room.getRoomno());
        }
    }//GEN-LAST:event_boxunitnoActionPerformed

    private void boxroomnoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_boxroomnoActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_boxroomnoActionPerformed

    private void txtstuidActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtstuidActionPerformed
        // TODO add your handling code here:
        this.txtstuid.setEditable(false);
    }//GEN-LAST:event_txtstuidActionPerformed

    private void formInternalFrameClosing(javax.swing.event.InternalFrameEvent evt) {//GEN-FIRST:event_formInternalFrameClosing
        // TODO add your handling code here:
        //删除掉map集合内的对象
        FrameUtil2.framemap.remove(StudentFrame.class.getName());
    }//GEN-LAST:event_formInternalFrameClosing

    private void btnintoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnintoActionPerformed
        // TODO add your handling code here:
       // String buildingno = this.txtbuildingno.getText().trim();
        String stuname =this.txtstuname.getText().trim();
        String stusex = this.txtstusex.getText().trim();
        String sage = this.txtstuage.getText().trim();
        Integer stuage = Integer.parseInt(sage);
        String stuschool = this.txtstuschool.getText().trim();
        String stuphone = this.txtstuphone.getText().trim();
        String stucard = this.txtstucard.getText().trim();
        String buildingno = (String)this.boxbuildingno.getSelectedItem();
        String unitno = (String)this.boxunitno.getSelectedItem();
        String roomno = (String)this.boxroomno.getSelectedItem();
        Student stu = new Student(stuname, stusex, stuage, stuschool, stuphone, stucard, buildingno, unitno, roomno,"未入住");
        boolean result = studentService.into(stu);
        if(result){
            JOptionPane.showMessageDialog(this, "添加成功");
            cancel();
            List<Student> list = studentService.findAll();
            refresh(list);
        }else
            JOptionPane.showMessageDialog(this, "添加失败");
        
    }//GEN-LAST:event_btnintoActionPerformed

    private void btncancelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btncancelActionPerformed
        // TODO add your handling code here:
        cancel();
    }//GEN-LAST:event_btncancelActionPerformed

    private void btnupdateActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnupdateActionPerformed
        // TODO add your handling code here:
        String sid = this.txtstuid.getText();
        Integer stuid = Integer.parseInt(sid);
        String stuname = this.txtstuname.getText();
        String stusex = this.txtstusex.getText();
        String sage = this.txtstuage.getText();
        Integer stuage = Integer.parseInt(sage);
        String stuschool = this.txtstuschool.getText();
        String stuphone = this.txtstuphone.getText();
        String stucard =this.txtstucard.getText();
        String buildingno = (String)this.boxbuildingno.getSelectedItem();
        String unitno = (String)this.boxunitno.getSelectedItem();
        String roomno = (String)this.boxroomno.getSelectedItem();
        Student student = new Student(stuid, stuname, stusex, stuage, stuschool, stuphone, stucard, buildingno, unitno, roomno);
        boolean result = studentService.update(student);
        if(result){
            JOptionPane.showMessageDialog(this, "修改成功");
            cancel();
            List<Student> list = studentService.findAll();
            refresh(list);
        }else
            JOptionPane.showMessageDialog(this, "修改失败");
    }//GEN-LAST:event_btnupdateActionPerformed

    private void tabStudentMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tabStudentMouseClicked
        // TODO add your handling code here:
//        int row =this.tabRoom.getSelectedRow();
//        //将选中行中的内容分别输入到下面的输入框中
//        this.txtroomid.setText(this.tabRoom.getValueAt(row, 0).toString());
        int row = this.tabStudent.getSelectedRow();
        this.txtstuid.setText(this.tabStudent.getValueAt(row, 0).toString());
        this.txtstuname.setText(this.tabStudent.getValueAt(row, 1).toString());
        this.txtstusex.setText(this.tabStudent.getValueAt(row, 2).toString());
        this.txtstuage.setText(this.tabStudent.getValueAt(row, 3).toString());
        this.txtstuschool.setText(this.tabStudent.getValueAt(row, 4).toString());
        this.txtstuphone.setText(this.tabStudent.getValueAt(row, 5).toString());
        this.txtstucard.setText(this.tabStudent.getValueAt(row, 6).toString());
        this.boxbuildingno.setSelectedItem(this.tabStudent.getValueAt(row, 7));
        this.boxunitno.setSelectedItem(this.tabStudent.getValueAt(row, 8));
        this.boxroomno.setSelectedItem(this.tabStudent.getValueAt(row, 9));
        
        this.btninto.setEnabled(false);
        
        this.btnupdate.setEnabled(true);
        this.btndelete.setEnabled(true);
    }//GEN-LAST:event_tabStudentMouseClicked

    private void btndeleteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btndeleteActionPerformed
        // TODO add your handling code here:
        String sid = this.txtstuid.getText();
        Integer stuid = Integer.parseInt(sid);
        
        boolean result = studentService.delete(stuid);
        if(result){
            JOptionPane.showMessageDialog(this, "删除成功");
            cancel();
            List<Student> list = studentService.findAll();
            refresh(list);
        }else
            JOptionPane.showMessageDialog(this, "删除失败");
    }//GEN-LAST:event_btndeleteActionPerformed
//显示窗口的公共方法
    
    private void refresh(List<Student> list) {
        DefaultTableModel dtm = (DefaultTableModel) this.tabStudent.getModel();
        while(dtm.getRowCount()>0){
            //从第0行开始删除
            dtm.removeRow(0);
        }//遍历集合
        for(Student stu : list){
            Vector v =new Vector();
            v.add(stu.getStuid());
            v.add(stu.getStuname());
            v.add(stu.getStusex());
            v.add(stu.getStuage());
            v.add(stu.getStuschool());
            v.add(stu.getStuphone());
            v.add(stu.getStucard());
            v.add(stu.getBuildingno());
            v.add(stu.getUnitno());
            v.add(stu.getRoomno());
            dtm.addRow(v);
        }
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JComboBox<String> boxbuildingno;
    private javax.swing.JComboBox<String> boxroomno;
    private javax.swing.JComboBox<String> boxunitno;
    private javax.swing.JButton btncancel;
    private javax.swing.JButton btndelete;
    private javax.swing.JButton btninto;
    private javax.swing.JButton btnupdate;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JRadioButtonMenuItem jRadioButtonMenuItem1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTable tabStudent;
    private javax.swing.JTextField txtstuage;
    private javax.swing.JTextField txtstucard;
    private javax.swing.JTextField txtstuid;
    private javax.swing.JTextField txtstuname;
    private javax.swing.JTextField txtstuphone;
    private javax.swing.JTextField txtstuschool;
    private javax.swing.JTextField txtstusex;
    // End of variables declaration//GEN-END:variables

    private void cancel() {
        this.txtstuid.setText("");
        this.txtstuname.setText("");
        this.txtstusex.setText("");
        this.txtstuage.setText("");
        this.txtstuschool.setText("");
        this.txtstuphone.setText("");
        this.txtstucard.setText("");
        this.boxbuildingno.removeAllItems();
        this.boxbuildingno.addItem("请选择");
        this.boxbuildingno.addItem("25");
        this.boxbuildingno.addItem("23");
        this.boxunitno.removeAllItems();
        this.boxunitno.addItem("请选择");
        this.boxroomno.removeAllItems();
        this.boxroomno.addItem("请选择");
        //启用按钮
        this.btninto.setEnabled(true);
        //禁用按钮
        this.btnupdate.setEnabled(false);
        this.btndelete.setEnabled(false);
        
        
    }

    
}
//显示窗体的公共方法
    

